package com.ruoyi.center.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.center.domain.AffiliatedUnit;
import com.ruoyi.center.service.IAffiliatedUnitService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 依托与共建单位Controller
 *
 * @author ruoyi
 * @date 2025-11-08
 */
@RestController
@RequestMapping("/center/unit")
public class AffiliatedUnitController extends BaseController
{
    @Autowired
    private IAffiliatedUnitService affiliatedUnitService;

    /**
     * 查询依托与共建单位列表
     */
    @PreAuthorize("@ss.hasPermi('center:unit:list')")
    @GetMapping("/list")
    public TableDataInfo list(AffiliatedUnit affiliatedUnit)
    {
        startPage();
        List<AffiliatedUnit> list = affiliatedUnitService.selectAffiliatedUnitList(affiliatedUnit);
        return getDataTable(list);
    }

    /**
     * 导出依托与共建单位列表
     */
    @PreAuthorize("@ss.hasPermi('center:unit:export')")
    @Log(title = "依托与共建单位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AffiliatedUnit affiliatedUnit)
    {
        List<AffiliatedUnit> list = affiliatedUnitService.selectAffiliatedUnitList(affiliatedUnit);
        ExcelUtil<AffiliatedUnit> util = new ExcelUtil<AffiliatedUnit>(AffiliatedUnit.class);
        util.exportExcel(response, list, "依托与共建单位数据");
    }

    /**
     * 获取依托与共建单位详细信息
     */
    @PreAuthorize("@ss.hasPermi('center:unit:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(affiliatedUnitService.selectAffiliatedUnitById(id));
    }

    /**
     * 新增依托与共建单位
     */
    @PreAuthorize("@ss.hasPermi('center:unit:add')")
    @Log(title = "依托与共建单位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AffiliatedUnit affiliatedUnit)
    {
        return toAjax(affiliatedUnitService.insertAffiliatedUnit(affiliatedUnit));
    }

    /**
     * 修改依托与共建单位
     */
    @PreAuthorize("@ss.hasPermi('center:unit:edit')")
    @Log(title = "依托与共建单位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AffiliatedUnit affiliatedUnit)
    {
        return toAjax(affiliatedUnitService.updateAffiliatedUnit(affiliatedUnit));
    }

    /**
     * 删除依托与共建单位
     */
    @PreAuthorize("@ss.hasPermi('center:unit:remove')")
    @Log(title = "依托与共建单位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(affiliatedUnitService.deleteAffiliatedUnitByIds(ids));
    }
}
